GTK: Fix build for pre-C99 compilers
authorChun-wei Fan <fanchunwei@src.gnome.org>
Mon, 9 May 2016 08:37:39 +0000 (16:37 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 10 May 2016 09:14:07 +0000 (17:14 +0800)
Some compilers we support, such as pre-2013 Visual Studio, does not support
for INIFINITY, log2() and exp2(), so check for exp2() and log2() during
configure, and use fallbacks for them and INIFINTY if they are not found.

https://bugzilla.gnome.org/show_bug.cgi?id=766207

config.h.win32.in
configure.ac
gtk/fallback-c89.c
gtk/gtkprogressbar.c
gtk/inspector/visual.c

index 8269db73e2752d261eeb0b24b50e0f76f236ed80..a73067e42025862b4b876eba283de384a00057ce 100644 (file)
 /* Define to 1 if you have the <dlfcn.h> header file. */
 /* #undef HAVE_DLFCN_H */
 
+/* Define to 1 if you have the `exp2' function. */
+#if !defined (_MSC_VER) || (_MSC_VER >= 1800)
+#define HAVE_EXP2 1
+#endif
+
 /* Define to 1 if you have the `flockfile' function. */
 #undef HAVE_FLOCKFILE
 
 /* Define to 1 if you have the `localtime_r' function. */
 /* #undef HAVE_LOCALTIME_R */
 
+/* Define to 1 if you have the `log2' function. */
+#if !defined (_MSC_VER) || (_MSC_VER >= 1800)
+#define HAVE_LOG2 1
+#endif
+
 /* Define to 1 if you have the `lstat' function. */
 /* #undef HAVE_LSTAT */
 
index 3718dbf89870f41de9cdea715a539c74d60b9ed8..2d4df249f56222b4f3056bdce05bc5fcc2eeaebf 100644 (file)
@@ -897,7 +897,7 @@ AC_TYPE_UID_T
 
 # Check for round(), rint(), isnan(), isinf() and nearbyint()
 AC_CHECK_LIB(m,round,,)
-AC_CHECK_FUNCS(round rint nearbyint sincos)
+AC_CHECK_FUNCS(round rint nearbyint sincos exp2 log2)
 AC_CHECK_DECLS([isnan, isinf], [], [], [[#include <math.h>]])
 
 # Checks for gdkspawn
index e87bf76c0c5395729349b856dd10a0a4bb5d8c54..df28048feb5a78750aaacea368ebe55c6273eb59 100644 (file)
@@ -77,3 +77,30 @@ isinf (double x)
   return (!_finite (x) && !_isnan (x));
 }
 #endif
+
+#ifndef INFINITY
+/* define INFINITY for compilers that lack support for it */
+# ifdef HUGE_VALF
+#  define INFINITY HUGE_VALF
+# else
+#  define INFINITY (float)HUGE_VAL
+# endif
+#endif
+
+#ifndef HAVE_LOG2
+/* Use a simple implementation for log2() for compilers that lack it */
+static inline double
+log2 (double x)
+{
+  return log (x) / log (2.0);
+}
+#endif
+
+#ifndef HAVE_EXP2
+/* Use a simple implementation for exp2() for compilers that lack it */
+static inline double
+exp2 (double x)
+{
+  return pow (2.0, x);
+}
+#endif
index 9ba2c86d1f60141aef52a4dde3203ffd56e7fffe..86c57a53188ca43baf011d72e10618508f6dc257 100644 (file)
@@ -25,7 +25,6 @@
 #include "config.h"
 
 #include <string.h>
-#include <math.h>
 
 #include "gtkprogressbar.h"
 #include "gtkorientableprivate.h"
@@ -42,6 +41,8 @@
 
 #include "a11y/gtkprogressbaraccessible.h"
 
+#include "fallback-c89.c"
+
 /**
  * SECTION:gtkprogressbar
  * @Short_description: A widget which indicates progress visually
index f56f66e993ca126586a09e21f5a5d6f78c19207a..b3da229a733651ddc9bbacd0cb2e45693c90fb47 100644 (file)
@@ -31,7 +31,7 @@
 #include "gtkwindow.h"
 #include "gtkcssproviderprivate.h"
 
-#include <math.h>
+#include "fallback-c89.c"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"